using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using EcsSiteDSTableAdapters;
using System.Collections.Generic;
using System.Text;

namespace SiteECSWeb
{
    [DataObject]
    public class EmpHistoryBLL
    {
        private EmpHistoryTableAdapter _EmpHistoryAdapter = null;

        protected EmpHistoryTableAdapter EmpHistoryAdapter
        {
            get
            {
                if (_EmpHistoryAdapter == null)
                {
                    _EmpHistoryAdapter = new EmpHistoryTableAdapter();
                }
                return _EmpHistoryAdapter;
            }
        }

        #region SelectEmpHistory
        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public EcsSiteDS.EmpHistoryDataTable GetAllEmpHistory()
        {
            return EmpHistoryAdapter.GetEmpHistoryRowRankData();
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.EmpHistoryDataTable GetEmpHistoryCurrentEcsHead()
        {
            return EmpHistoryAdapter.GetEmpHistoryCurrentEcsHeadData();
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.EmpHistoryDataTable GetEmpHistoryCurrentEmpOffices()
        {
            return EmpHistoryAdapter.GetEmpHistoryCurrentEmpOfficesData();
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.EmpHistoryDataTable GetEmpHistoryCurrentEmpDep()
        {
            return EmpHistoryAdapter.GetEmpHistoryDataCurrentEmpDep();
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.EmpHistoryDataTable GetEmpHistoryCurrentEmpOther()
        {
            return EmpHistoryAdapter.GetEmpHistoryCurrentOtherData();
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.EmpHistoryDataTable GetEmpHistoryByEmpHisID(int EmpOffPst_id)
        {
            return EmpHistoryAdapter.GetEmpHistoryDataByEmpOffPstid(EmpOffPst_id);
            
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.EmpHistoryDataTable GetEmpHistoryByEmpID(int Ecsemp_id)
        {
            return EmpHistoryAdapter.GetEmpHistoryDataByEmpId(Ecsemp_id);

        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.EmpHistoryDataTable GetEmpHisDepByEmpID(int Ecsemp_id)
        {
            return EmpHistoryAdapter.GetEmpHisEmpDepDataByEmpId(Ecsemp_id);
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.EmpHistoryDataTable GetEmpHisOffByEmpID(int Ecsemp_id)
        {
            return EmpHistoryAdapter.GetEmpHisEmpOffDataByEmpId(Ecsemp_id);
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.EmpHistoryDataTable GetEmpHistoryByCityID(int City_id)
        {
            return EmpHistoryAdapter.GetEmpHistoryDataByCityId(City_id);
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.EmpHistoryDataTable
            GetEmpHistoryCurrentHeadOfficesByCityID(int City_id)
        {
            return EmpHistoryAdapter.GetEmpHistoryCurrentHeadDataByCityId(City_id);
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.EmpHistoryDataTable
            GetEmpHistoryCurrentEmpDepByDepCatId(int DepCat_id)
        {
            return EmpHistoryAdapter.GetEmpHistoryCurrentEmpDepDataByDepCatId(DepCat_id);
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.EmpHistoryDataTable
            GetEmpHistoryCurrentEmpDepByEmpPostitionId(int EmpPostition_Id)
        {
            return EmpHistoryAdapter.GetEmpHistoryCurrentEmpDepDataByEmpPostitionId(EmpPostition_Id);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.EmpHistoryDataTable
            GetEmpHistoryCurrentEmpDepByEmpTitleId(int EmpTitle_id)
        {
            return EmpHistoryAdapter.GetEmpHistoryCurrentEmpDepDataByEmpTitleId(EmpTitle_id);
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public List<EmpHistoryInfo> GetEmpHistoryCurrentEmpDepAdvanced(int DepID, int EmpTitleId,
            int EmpPostitionId,
            string EmpNameToFind)
        {

            List<EmpHistoryInfo> EmpHisList = new List<EmpHistoryInfo>();
          
            StringBuilder sbCode = new StringBuilder();
            string expression = string.Empty;

            EcsSiteDS.EmpHistoryDataTable EmpHisTable =
                            EmpHistoryAdapter.GetEmpHistoryDataCurrentEmpDep();
            
            if (!string.IsNullOrEmpty(EmpNameToFind)
                || DepID > 0 || EmpTitleId > 0 || EmpPostitionId > 0)
            {
                if (!string.IsNullOrEmpty(EmpNameToFind))
                {
                    sbCode.Append("(Ecsemp_nmar LIKE'%" + EmpNameToFind + "%') AND ");
                }
                if (DepID > 0)
                {
                     sbCode.Append("(DepCat_id =" + DepID + ") AND ");
                }
                if (EmpTitleId > 0)
                {
                     sbCode.Append("(EmpTitle_id =" + EmpTitleId + ") AND ");
                }
                if (EmpPostitionId > 0)
                {
                     sbCode.Append("(EmpPostition_Id =" + EmpPostitionId + ") AND ");
                }
                if (sbCode.ToString().EndsWith(" AND "))
                {
                    expression = sbCode.ToString().Substring(0, sbCode.Length - 5);
                }
                DataView dv = new DataView((DataTable)EmpHisTable);

                dv.RowFilter= expression;
                foreach (DataRowView EmpHisRow in dv)
                {
                    EmpHistoryInfo _empHisInfo =
                    new EmpHistoryInfo((int)EmpHisRow["EmpOffPst_id"],
                        (long)EmpHisRow["RowRank"],
                        string.IsNullOrEmpty((string)EmpHisRow["DepNmAr"]) ? string.Empty : (string)EmpHisRow["DepNmAr"],
                        (string)EmpHisRow["Ecsemp_nmar"], (int)EmpHisRow["Ecsemp_id"],
                        (string)EmpHisRow["EmpTitle_ar"], (int)EmpHisRow["EmpTitle_id"],
                        (string)EmpHisRow["EmpPostition_NameAr"],
                        (string)EmpHisRow["CityNmAr"], (int)EmpHisRow["City_id"],
                        (DateTime)EmpHisRow["EmpOffPst_SDate"]);
                    EmpHisList.Add(_empHisInfo);
                }
            }
            else
            {
                foreach (EcsSiteDS.EmpHistoryRow EmpHisRow in EmpHisTable)
                {
                    EmpHistoryInfo _empHisInfo =
                     new EmpHistoryInfo(EmpHisRow.EmpOffPst_id,
                     EmpHisRow.RowRank, (EmpHisRow.IsDepNmArNull()) ? string.Empty : EmpHisRow.DepNmAr,
                         EmpHisRow.Ecsemp_nmar, EmpHisRow.Ecsemp_id, EmpHisRow.EmpTitle_ar, EmpHisRow.EmpTitle_id,
                         EmpHisRow.EmpPostition_NameAr, EmpHisRow.CityNmAr,
                         EmpHisRow.City_id, EmpHisRow.EmpOffPst_SDate);
                    EmpHisList.Add(_empHisInfo);
                }
            }

            return EmpHisList;
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public List<EmpHistoryInfo> GetEmpHistoryCurrentEmpOtherAdvanced(int EmpTitleId,
            string EmpNameToFind)
        {

            List<EmpHistoryInfo> EmpHisList = new List<EmpHistoryInfo>();

            StringBuilder sbCode = new StringBuilder();
            string expression = string.Empty;

            EcsSiteDS.EmpHistoryDataTable EmpHisTable =
                            EmpHistoryAdapter.GetEmpHistoryCurrentOtherData();

            if (!string.IsNullOrEmpty(EmpNameToFind)
              || EmpTitleId > 0 )
            {
                if (!string.IsNullOrEmpty(EmpNameToFind))
                {
                    sbCode.Append("(Ecsemp_nmar LIKE'" + EmpNameToFind + "%') AND ");
                }
               
                if (EmpTitleId > 0)
                {
                    sbCode.Append("(EmpTitle_id =" + EmpTitleId + ") AND ");
                }
                
                if (sbCode.ToString().EndsWith(" AND "))
                {
                    expression = sbCode.ToString().Substring(0, sbCode.Length - 5);
                }
                DataView dv = new DataView((DataTable)EmpHisTable);

                dv.RowFilter = expression;
                foreach (DataRowView EmpHisRow in dv)
                {
                    EmpHistoryInfo _empHisInfo =
                    new EmpHistoryInfo((int)EmpHisRow["EmpOffPst_id"],
                        (long)EmpHisRow["RowRank"],
                        (string)EmpHisRow["Ecsemp_nmar"], (int)EmpHisRow["Ecsemp_id"],
                        (string)EmpHisRow["EmpTitle_ar"], (int)EmpHisRow["EmpTitle_id"],
                        string.Empty,int.MinValue,
                         //(string.IsNullOrEmpty((string)EmpHisRow["CityNmAr"])) ? string.Empty : (string)EmpHisRow["CityNmAr"],
                         //(EmpHisRow["City_id"] == System.DBNull.Value) ? 0 : (int)EmpHisRow["City_id"],
                        (string)EmpHisRow["EmpOffPst_Notes"],
                        (DateTime)EmpHisRow["EmpOffPst_SDate"]);
                    EmpHisList.Add(_empHisInfo);
                }
            }
            else
            {
                foreach (EcsSiteDS.EmpHistoryRow EmpHisRow in EmpHisTable)
                {
                    EmpHistoryInfo _empHisInfo =
                     new EmpHistoryInfo(EmpHisRow.EmpOffPst_id,
                     EmpHisRow.RowRank, 
                         EmpHisRow.Ecsemp_nmar, EmpHisRow.Ecsemp_id, EmpHisRow.EmpTitle_ar, EmpHisRow.EmpTitle_id,
                        (EmpHisRow.IsCityNmArNull() ? string.Empty : EmpHisRow.CityNmAr), EmpHisRow.City_id, 
                         EmpHisRow.EmpOffPst_Notes,
                         EmpHisRow.EmpOffPst_SDate);
                    EmpHisList.Add(_empHisInfo);
                }
            }

            return EmpHisList;
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public List<EmpHistoryInfo> GetEmpHistoryCurrentEmpOffAdvanced(int CityID, int EmpTitleId,
            int EmpPostitionId,
            string EmpNameToFind)
        {

            List<EmpHistoryInfo> EmpHisList = new List<EmpHistoryInfo>();
         
            StringBuilder sbCode = new StringBuilder();
            string expression = string.Empty;

            EcsSiteDS.EmpHistoryDataTable EmpHisTable =
                            EmpHistoryAdapter.GetEmpHistoryCurrentEmpOfficesData();

            if (!string.IsNullOrEmpty(EmpNameToFind)
                || CityID > 0 || EmpTitleId > 0 || EmpPostitionId > 0)
            {
                if (!string.IsNullOrEmpty(EmpNameToFind))
                {
                    sbCode.Append("(Ecsemp_nmar LIKE'%" + EmpNameToFind + "%') AND ");
                }
                if (CityID > 0)
                {
                    sbCode.Append("(City_id =" + CityID + ") AND ");
                }
                if (EmpTitleId > 0)
                {
                    sbCode.Append("(EmpTitle_id =" + EmpTitleId + ") AND ");
                }
                if (EmpPostitionId > 0)
                {
                    sbCode.Append("(EmpPostition_Id =" + EmpPostitionId + ") AND ");
                }
                if (sbCode.ToString().EndsWith(" AND "))
                {
                    expression = sbCode.ToString().Substring(0, sbCode.Length - 5);
                }
                DataView dv = new DataView((DataTable)EmpHisTable);

                dv.RowFilter = expression;
                foreach (DataRowView EmpHisRow in dv)
                {
                    EmpHistoryInfo _empHisInfo =
                    //new EmpHistoryInfo((int)EmpHisRow["EmpOffPst_id"],
                    //    (long)EmpHisRow["RowRank"],
                    //    string.IsNullOrEmpty((string)EmpHisRow["DepNmAr"]) ? string.Empty : (string)EmpHisRow["DepNmAr"],
                    //    (string)EmpHisRow["Ecsemp_nmar"], (int)EmpHisRow["Ecsemp_id"],
                    //    (string)EmpHisRow["EmpTitle_ar"], (int)EmpHisRow["EmpTitle_id"],
                    //    (string)EmpHisRow["EmpPostition_NameAr"],
                    //    (string)EmpHisRow["CityNmAr"], (int)EmpHisRow["City_id"],
                    //    (DateTime)EmpHisRow["EmpOffPst_SDate"]);
                     new EmpHistoryInfo((int)EmpHisRow["EmpOffPst_id"],
                        (long)EmpHisRow["RowRank"],string.Empty,
                        (string)EmpHisRow["Ecsemp_nmar"], (int)EmpHisRow["Ecsemp_id"],
                        (string)EmpHisRow["EmpTitle_ar"], (int)EmpHisRow["EmpTitle_id"],
                        (string)EmpHisRow["EmpPostition_NameAr"],
                        (string.IsNullOrEmpty((string)EmpHisRow["CityNmAr"])) ? string.Empty : (string)EmpHisRow["CityNmAr"]
                        , (int)EmpHisRow["City_id"],
                        (DateTime)EmpHisRow["EmpOffPst_SDate"]);
                    EmpHisList.Add(_empHisInfo);
                }
            }
            else
            {
                foreach (EcsSiteDS.EmpHistoryRow EmpHisRow in EmpHisTable)
                {
                    EmpHistoryInfo _empHisInfo =
                    new EmpHistoryInfo(EmpHisRow.EmpOffPst_id,
                    EmpHisRow.RowRank, (EmpHisRow.IsDepNmArNull()) ? string.Empty : EmpHisRow.DepNmAr ,
                        EmpHisRow.Ecsemp_nmar, EmpHisRow.Ecsemp_id,EmpHisRow.EmpTitle_ar,EmpHisRow.EmpTitle_id,
                        EmpHisRow.EmpPostition_NameAr,
                        (EmpHisRow.IsCityNmArNull() ? string.Empty: EmpHisRow.CityNmAr),
                        EmpHisRow.City_id,EmpHisRow.EmpOffPst_SDate);
                    EmpHisList.Add(_empHisInfo);
                }
            }

            return EmpHisList;
        }
        //[DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        //public List<EmpHistoryInfo> GetEmpHistoryCurrentEmpDepAdvanced(int DepID, int EmpTitleId,
        //    int EmpPostitionId,
        //    string EmpNameToFind)
        //{
        //    List<EmpHistoryInfo> EmpHisList = new List<EmpHistoryInfo>();
        //    int len = EmpNameToFind == null ? 0 : EmpNameToFind.Length;

        //    if (!string.IsNullOrEmpty(EmpNameToFind)
        //        || DepID > 0 || EmpTitleId > 0 || EmpPostitionId > 0)
        //    {
        //        if (!string.IsNullOrEmpty(EmpNameToFind))
        //        {
        //            if (DepID <= 0)
        //            {
        //                EcsSiteDS.EmpHistoryDataTable EmpHisTable =
        //                    EmpHistoryAdapter.GetEmpHistoryDataCurrentEmpDep();
        //                foreach (EcsSiteDS.EmpHistoryRow EmpHisRow in EmpHisTable)
        //                {
        //                    EmpHistoryInfo _empHisInfo =
        //                    new EmpHistoryInfo(EmpHisRow.EmpOffPst_id,
        //                        EmpHisRow.RowRank, EmpHisRow.DepNmAr,
        //                        EmpHisRow.Ecsemp_nmar, EmpHisRow.EmpTitle_ar,
        //                        EmpHisRow.EmpPostition_NameAr, EmpHisRow.EmpOffPst_SDate);

        //                    int compareLength = Math.Min(len, EmpHisRow.Ecsemp_nmar.Length);

        //                    if (EmpHisRow.Ecsemp_nmar.Substring(0, compareLength).
        //                        ToLower().Equals(EmpNameToFind.Substring(0, compareLength).ToLower())
        //                        && EmpHisRow.Ecsemp_nmar.Length >= len)
        //                    {
        //                        EmpHisList.Add(_empHisInfo);
        //                    }
        //                }
        //            }
        //            else
        //            {
        //                EcsSiteDS.EmpHistoryDataTable EmpHisTable =
        //                    EmpHistoryAdapter.GetEmpHistoryCurrentEmpDepDataByDepCatId(DepID);
        //                foreach (EcsSiteDS.EmpHistoryRow EmpHisRow in EmpHisTable)
        //                {
        //                    EmpHistoryInfo _empHisInfo =
        //                        new EmpHistoryInfo(EmpHisRow.EmpOffPst_id,
        //                        EmpHisRow.RowRank, EmpHisRow.DepNmAr,
        //                        EmpHisRow.Ecsemp_nmar, EmpHisRow.EmpTitle_ar,
        //                        EmpHisRow.EmpPostition_NameAr, EmpHisRow.EmpOffPst_SDate);

        //                    int compareLength = Math.Min(len, EmpHisRow.Ecsemp_nmar.Length);

        //                    if (EmpHisRow.Ecsemp_nmar.Substring(0, compareLength).
        //                        ToLower().Equals(EmpNameToFind.Substring(0, compareLength).ToLower())
        //                        && EmpHisRow.Ecsemp_nmar.Length >= len)
        //                    {
        //                        EmpHisList.Add(_empHisInfo);
        //                    }
        //                }
        //            }
        //        }
        //        if (DepID > 0)
        //        {
        //            EcsSiteDS.EmpHistoryDataTable EmpHisTable =
        //                   EmpHistoryAdapter.GetEmpHistoryCurrentEmpDepDataByDepCatId(DepID);
        //            foreach (EcsSiteDS.EmpHistoryRow EmpHisRow in EmpHisTable)
        //            {
        //                EmpHistoryInfo _empHisInfo =
        //                    new EmpHistoryInfo(EmpHisRow.EmpOffPst_id,
        //                    EmpHisRow.RowRank, EmpHisRow.DepNmAr,
        //                    EmpHisRow.Ecsemp_nmar, EmpHisRow.EmpTitle_ar,
        //                    EmpHisRow.EmpPostition_NameAr, EmpHisRow.EmpOffPst_SDate);
        //                EmpHisList.Add(_empHisInfo);
        //            }
        //        }
        //        if (EmpTitleId > 0)
        //        {
        //            EcsSiteDS.EmpHistoryDataTable EmpHisTable =
        //                   EmpHistoryAdapter.GetEmpHistoryCurrentEmpDepDataByDepCatId(DepID);
        //            foreach (EcsSiteDS.EmpHistoryRow EmpHisRow in EmpHisTable)
        //            {
        //                EmpHistoryInfo _empHisInfo =
        //                    new EmpHistoryInfo(EmpHisRow.EmpOffPst_id,
        //                    EmpHisRow.RowRank, EmpHisRow.DepNmAr,
        //                    EmpHisRow.Ecsemp_nmar, EmpHisRow.EmpTitle_ar,
        //                    EmpHisRow.EmpPostition_NameAr, EmpHisRow.EmpOffPst_SDate);
        //                EmpHisList.Add(_empHisInfo);
        //            }
        //        }
        //    }
        //    else
        //    {
        //        EcsSiteDS.EmpHistoryDataTable EmpHisTable =
        //                    EmpHistoryAdapter.GetEmpHistoryDataCurrentEmpDep();
        //        foreach (EcsSiteDS.EmpHistoryRow EmpHisRow in EmpHisTable)
        //        {
        //            EmpHistoryInfo _empHisInfo =
        //            new EmpHistoryInfo(EmpHisRow.EmpOffPst_id,
        //                EmpHisRow.RowRank, EmpHisRow.DepNmAr,
        //                EmpHisRow.Ecsemp_nmar, EmpHisRow.EmpTitle_ar,
        //                EmpHisRow.EmpPostition_NameAr, EmpHisRow.EmpOffPst_SDate);
        //            EmpHisList.Add(_empHisInfo);
        //        }
        //    }

        //    return EmpHisList;
        //}


        //[DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        //public EcsSiteDS.EmpHistoryDataTable usp_GetAllEmpCurntOffDeails()
        //{
        //    return EmpHistoryAdapter.GetEmpCurntWithEmpNmOffDataDeails();

        //}

        //[DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        //public EcsSiteDS.EmpHistoryDataTable GetAllEmpCurntOffDeailsByOfficeId(int OfficeId)
        //{

        //   return EmpHistoryAdapter.GetEmpCurntWithEmpNmOffDeailsDataByOfficeID(OfficeId);
        //}

        //[DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        //public EcsSiteDS.EmpHistoryDataTable GetCurrentEmpOffDataByCityID(int CityID)
        //{
        //    return EmpHistoryAdapter.GetCurrentEmpOffDataByCityID(CityID);
        //}

        //[DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        //public EcsSiteDS.EmpHistoryDataTable GetCurrentEmpOffDataByCityName(string CityNmEn)
        //{
        //    return EmpHistoryAdapter.GetCurrentEmpOffDataByCityName(CityNmEn);
        //}

        #endregion

        #region insertEmpHistory
        [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
        public bool AddEmpHistory(int Ecsemp_id, int? City_id, DateTime? EmpOffPst_SDate,
            DateTime? EmpOffPst_EDate, int EmpPostition_Id, string EmpOffPst_Notes,
            string EmpOffPst_DecisionNum, int? DepCat_id, int EmpTitle_id)
        {
            EcsSiteDS.EmpHistoryDataTable EmpHistoryTable = new EcsSiteDS.EmpHistoryDataTable();
            EcsSiteDS.EmpHistoryRow EmpHistory_Row = EmpHistoryTable.NewEmpHistoryRow();

            if (EmpOffPst_SDate == null) EmpHistory_Row.SetEmpOffPst_SDateNull(); else EmpHistory_Row.EmpOffPst_SDate = EmpOffPst_SDate.Value;
            if (EmpOffPst_EDate == null) EmpHistory_Row.SetEmpOffPst_EDateNull(); else EmpHistory_Row.EmpOffPst_EDate = EmpOffPst_EDate.Value;
            if (EmpOffPst_Notes == null) EmpHistory_Row.SetEmpOffPst_NotesNull(); else EmpHistory_Row.EmpOffPst_Notes = EmpOffPst_Notes;
            if (string.IsNullOrEmpty(EmpOffPst_DecisionNum)) EmpHistory_Row.SetEmpOffPst_DecisionNumNull(); else EmpHistory_Row.EmpOffPst_DecisionNum = EmpOffPst_DecisionNum;
            if (DepCat_id == null) EmpHistory_Row.SetDepCat_idNull(); else EmpHistory_Row.DepCat_id = DepCat_id.Value;
            if (City_id == null) EmpHistory_Row.SetCity_idNull(); else EmpHistory_Row.City_id = City_id.Value;

            EmpHistory_Row.Ecsemp_id = Ecsemp_id;
            EmpHistory_Row.EmpPostition_Id = EmpPostition_Id;
            EmpHistory_Row.EmpTitle_id = EmpTitle_id;

            EmpHistoryTable.AddEmpHistoryRow(EmpHistory_Row);

            int rowsAffected = EmpHistoryAdapter.Update(EmpHistoryTable);

            return rowsAffected == 1;

        }
        [DataObjectMethodAttribute(DataObjectMethodType.Insert, false)]
        public bool AddEmpHistory(int Ecsemp_id, int? City_id, DateTime? EmpOffPst_SDate,
            int EmpPostition_Id,
            string EmpOffPst_DecisionNum, int? DepCat_id, int EmpTitle_id, string EmpOffPst_Notes)
        {
            EcsSiteDS.EmpHistoryDataTable EmpHistoryTable = new EcsSiteDS.EmpHistoryDataTable();
            EcsSiteDS.EmpHistoryRow EmpHistory_Row = EmpHistoryTable.NewEmpHistoryRow();

            if (EmpOffPst_SDate == null) EmpHistory_Row.SetEmpOffPst_SDateNull(); else EmpHistory_Row.EmpOffPst_SDate = EmpOffPst_SDate.Value;
            if (string.IsNullOrEmpty(EmpOffPst_Notes)) EmpHistory_Row.SetEmpOffPst_NotesNull(); else EmpHistory_Row.EmpOffPst_Notes = EmpOffPst_Notes;
            if (DepCat_id == null) EmpHistory_Row.SetDepCat_idNull(); else EmpHistory_Row.DepCat_id = DepCat_id.Value;
            if (City_id == null) EmpHistory_Row.SetCity_idNull(); else EmpHistory_Row.City_id = City_id.Value;
            if (string.IsNullOrEmpty(EmpOffPst_DecisionNum)) EmpHistory_Row.SetEmpOffPst_DecisionNumNull(); else EmpHistory_Row.EmpOffPst_DecisionNum = EmpOffPst_DecisionNum;

            EmpHistory_Row.Ecsemp_id = Ecsemp_id;
            EmpHistory_Row.EmpPostition_Id = EmpPostition_Id;
            EmpHistory_Row.EmpTitle_id = EmpTitle_id;

            EmpHistoryTable.AddEmpHistoryRow(EmpHistory_Row);
            int rowsAffected = EmpHistoryAdapter.Update(EmpHistoryTable);
            return rowsAffected == 1;

        }
        [DataObjectMethodAttribute(DataObjectMethodType.Insert, false)]
        public bool AddEmpHistory(int Ecsemp_id, int? City_id, DateTime? EmpOffPst_SDate,           
            string EmpOffPst_DecisionNum, int? DepCat_id, int EmpTitle_id, int? EmpPostType_Id, 
            string EmpOffPst_Notes)
        {
            EcsSiteDS.EmpHistoryDataTable EmpHistoryTable = new EcsSiteDS.EmpHistoryDataTable();
            EcsSiteDS.EmpHistoryRow EmpHistory_Row = EmpHistoryTable.NewEmpHistoryRow();

            if (EmpOffPst_SDate == null) EmpHistory_Row.SetEmpOffPst_SDateNull(); else EmpHistory_Row.EmpOffPst_SDate = EmpOffPst_SDate.Value;
            if (string.IsNullOrEmpty(EmpOffPst_Notes)) EmpHistory_Row.SetEmpOffPst_NotesNull(); else EmpHistory_Row.EmpOffPst_Notes = EmpOffPst_Notes;
            if (DepCat_id == null) EmpHistory_Row.SetDepCat_idNull(); else EmpHistory_Row.DepCat_id = DepCat_id.Value;
            if (City_id == null) EmpHistory_Row.SetCity_idNull(); else EmpHistory_Row.City_id = City_id.Value;
            if (EmpPostType_Id == null) EmpHistory_Row.SetEmpPostType_IdNull(); else EmpHistory_Row.EmpPostType_Id = EmpPostType_Id.Value;
            if (string.IsNullOrEmpty(EmpOffPst_DecisionNum)) EmpHistory_Row.SetEmpOffPst_DecisionNumNull(); else EmpHistory_Row.EmpOffPst_DecisionNum = EmpOffPst_DecisionNum;

            EmpHistory_Row.Ecsemp_id = Ecsemp_id;            
            EmpHistory_Row.EmpTitle_id = EmpTitle_id;
            EmpHistoryTable.AddEmpHistoryRow(EmpHistory_Row);
            int rowsAffected = EmpHistoryAdapter.Update(EmpHistoryTable);
            
            return rowsAffected == 1;

        }

        #endregion

        #region UpdateEmpHistory
        [DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
        public bool UpdateEmpHistory(int Ecsemp_id, int? City_id, DateTime? EmpOffPst_SDate,
            DateTime? EmpOffPst_EDate, int EmpPostition_Id, string EmpOffPst_Notes,
            string EmpOffPst_DecisionNum, int? DepCat_id, int EmpTitle_id, int EmpOffPst_id)
        {
            EcsSiteDS.EmpHistoryDataTable EmpHistoryTable = EmpHistoryAdapter.GetEmpHistoryDataByEmpOffPstid(EmpOffPst_id);
            if (EmpHistoryTable.Count == 0)
            {
                return false;
            }

            EcsSiteDS.EmpHistoryRow EmpHistory_Row = EmpHistoryTable[0];

            if (EmpOffPst_SDate == null) EmpHistory_Row.SetEmpOffPst_SDateNull(); else EmpHistory_Row.EmpOffPst_SDate = EmpOffPst_SDate.Value;
            if (EmpOffPst_EDate == null) EmpHistory_Row.SetEmpOffPst_EDateNull(); else EmpHistory_Row.EmpOffPst_EDate = EmpOffPst_EDate.Value;
            if (EmpOffPst_Notes == null) EmpHistory_Row.SetEmpOffPst_NotesNull(); else EmpHistory_Row.EmpOffPst_Notes = EmpOffPst_Notes;
            if (EmpOffPst_DecisionNum == null) EmpHistory_Row.SetEmpOffPst_DecisionNumNull(); else EmpHistory_Row.EmpOffPst_DecisionNum = EmpOffPst_DecisionNum;
            if (DepCat_id == null) EmpHistory_Row.SetDepCat_idNull(); else EmpHistory_Row.DepCat_id = DepCat_id.Value;
            if (City_id == null) EmpHistory_Row.SetCity_idNull(); else EmpHistory_Row.City_id = City_id.Value;

            EmpHistory_Row.Ecsemp_id = Ecsemp_id;
            EmpHistory_Row.EmpPostition_Id = EmpPostition_Id;
            EmpHistory_Row.EmpTitle_id = EmpTitle_id;
            EmpHistory_Row.EmpOffPst_id = EmpOffPst_id;

            int rowsAffected = EmpHistoryAdapter.Update(EmpHistory_Row);

            return rowsAffected == 1;
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
        public bool UpdateEmpHistory(int? City_id, DateTime? EmpOffPst_SDate,
            int? EmpPostition_Id, string EmpOffPst_Notes,
            string EmpOffPst_DecisionNum, int? DepCat_id, int EmpTitle_id, int EmpOffPst_id)
        {
            EcsSiteDS.EmpHistoryDataTable EmpHistoryTable = 
                EmpHistoryAdapter.GetEmpHistoryDataByEmpOffPstid(EmpOffPst_id);
            if (EmpHistoryTable.Count == 0)
            {
                return false;
            }

            EcsSiteDS.EmpHistoryRow EmpHistory_Row = EmpHistoryTable[0];

            if (EmpOffPst_SDate == null) EmpHistory_Row.SetEmpOffPst_SDateNull(); else EmpHistory_Row.EmpOffPst_SDate = EmpOffPst_SDate.Value;            
            if (EmpOffPst_Notes == null) EmpHistory_Row.SetEmpOffPst_NotesNull(); else EmpHistory_Row.EmpOffPst_Notes = EmpOffPst_Notes;
            if (EmpOffPst_DecisionNum == null) EmpHistory_Row.SetEmpOffPst_DecisionNumNull(); else EmpHistory_Row.EmpOffPst_DecisionNum = EmpOffPst_DecisionNum;if (EmpOffPst_DecisionNum == null) EmpHistory_Row.SetEmpOffPst_DecisionNumNull(); else EmpHistory_Row.EmpOffPst_DecisionNum = EmpOffPst_DecisionNum;
            if (EmpPostition_Id == null) EmpHistory_Row.SetEmpPostition_IdNull(); else EmpHistory_Row.EmpPostition_Id = EmpPostition_Id.Value ;


            if (DepCat_id == null)
            {
                //City_id = 2175;
                EmpHistory_Row.SetDepCat_idNull();
            }
            else
            {
                EmpHistory_Row.DepCat_id = DepCat_id.Value;
            }

            if (City_id == null) EmpHistory_Row.SetCity_idNull(); else EmpHistory_Row.City_id = City_id.Value;
            
            //EmpHistory_Row.EmpPostition_Id = EmpPostition_Id;
            
            EmpHistory_Row.EmpTitle_id = EmpTitle_id;

            int rowsAffected = EmpHistoryAdapter.Update(EmpHistory_Row);

            return rowsAffected == 1;
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Update, false)]
        public bool UpdateEmpHistory(DateTime? EmpOffPst_EDate, string EmpOffPst_Notes,
            int? EmpPostType_Id,
            int EmpOffPst_id)
        {
            EcsSiteDS.EmpHistoryDataTable EmpHistoryTable = 
                EmpHistoryAdapter.GetEmpHistoryDataByEmpOffPstid(EmpOffPst_id);
            if (EmpHistoryTable.Count == 0)
            {
                return false;
            }
            EcsSiteDS.EmpHistoryRow EmpHistory_Row = EmpHistoryTable[0];

            if (EmpOffPst_EDate == null) EmpHistory_Row.SetEmpOffPst_EDateNull(); else EmpHistory_Row.EmpOffPst_EDate = EmpOffPst_EDate.Value;
            if (EmpPostType_Id == null) EmpHistory_Row.SetEmpPostType_IdNull(); else EmpHistory_Row.EmpPostType_Id = EmpPostType_Id.Value;
            if (string.IsNullOrEmpty(EmpOffPst_Notes)) EmpHistory_Row.SetEmpOffPst_NotesNull(); else EmpHistory_Row.EmpOffPst_Notes = EmpOffPst_Notes;

            int rowsAffected = EmpHistoryAdapter.Update(EmpHistory_Row);

            return rowsAffected == 1;
        }


        [DataObjectMethodAttribute(DataObjectMethodType.Update, false)]
        public bool UpdateEmpHistory(DateTime? EmpOffPst_SDate, DateTime? EmpOffPst_EDate,
            int? DepCat_id, int? City_id, int? EmpPostType_Id, int EmpOffPst_id)
        {
            EcsSiteDS.EmpHistoryDataTable EmpHistoryTable =
                EmpHistoryAdapter.GetEmpHistoryDataByEmpOffPstid(EmpOffPst_id);
            if (EmpHistoryTable.Count == 0)
            {
                return false;
            }
            EcsSiteDS.EmpHistoryRow EmpHistory_Row = EmpHistoryTable[0];

            if (EmpOffPst_SDate == null) EmpHistory_Row.SetEmpOffPst_SDateNull(); else EmpHistory_Row.EmpOffPst_SDate = EmpOffPst_SDate.Value;
            if (EmpOffPst_EDate == null) EmpHistory_Row.SetEmpOffPst_EDateNull(); else EmpHistory_Row.EmpOffPst_EDate = EmpOffPst_EDate.Value;
            if (DepCat_id == null) EmpHistory_Row.SetDepCat_idNull(); else EmpHistory_Row.DepCat_id = DepCat_id.Value;
            if (City_id == null) EmpHistory_Row.SetCity_idNull(); else EmpHistory_Row.City_id = City_id.Value;
            if (EmpPostType_Id == null) EmpHistory_Row.SetEmpPostType_IdNull(); else EmpHistory_Row.EmpPostType_Id = EmpPostType_Id.Value;

            int rowsAffected = EmpHistoryAdapter.Update(EmpHistory_Row);

            return rowsAffected == 1;
        }

        #endregion

        #region DeleteEmpHistory
        [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
        public bool DeleteEmpHistory(int EmpOffPst_id)
        {
            int rowsAffected = EmpHistoryAdapter.Delete(EmpOffPst_id);
            return rowsAffected == 1;
        }
        #endregion
    }

}
